<?php

namespace App\Http\Services;

use App\Lib\CommonPrivateMsg;
use App\Lib\CommonSystemMsg;
use App\Lib\rc;

/**
 * 私聊信息服务
 *
 * Created on 2021/12/14 14:56
 * @Author <yuxiang.zhu@asiainnovations.net>
 */
class CommonPrivateMsgServices extends CommonServices
{
    /**
     * 融云实例
     *
     * @var rc
     */
    private $libRCloud;

    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->libRCloud = new rc();//实例化融云
    }

    /**
     * 通用发系统消息, k值需要在app/Lib/CommonSystemMsg中定义好，方便查找
     * 消息要拉平
     *
     * @param int $fromUserId
     * @param int $toUserId
     * @param int $k k值
     * @param array $data 数据
     * @param string $objectName
     * @return bool
     */
    public function sendPrivateMsg(int $fromUserId, int $toUserId, int $k, array $data, string $objectName = ''): bool
    {
        if (!in_array($k, CommonPrivateMsg::getK())) {
            return false;
        }

        $data = array_merge(['k' => $k], $data);
        return $this->libRCloud->send_private_msg($fromUserId, $toUserId, $objectName, $data);
    }
}